package com.itguigu.rabbitmq.six;

import com.itguigu.rabbitmq.utils.RabbitMqutil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Date 2021/7/18 21:32
 * @Created by wangle
 * @Description
 */
public class Receivedirectlogs {

    public static final String exchange_name = "direct_logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqutil.getChannel();
        //声明一个交换机
        channel.exchangeDeclare(exchange_name, BuiltinExchangeType.DIRECT);
        //声明一个队列
        channel.queueDeclare("console", false, false, false, null);

        channel.queueBind("console", exchange_name, "info");
        channel.queueBind("console", exchange_name, "warning");

        //声明 接受消息
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println(new String(message.getBody()));

        };

        //取消消息时的回调
        CancelCallback cancelCallback = (consumerTag) -> {

            System.out.println("消息消费被中断");
        };
        //消费者取消息时的回调接口
        channel.basicConsume("console", true, deliverCallback, cancelCallback);

    }
}
